
package com.scs.application.modules.msg.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.core.utils.UserUtils;
import com.scs.application.modules.msg.entity.Receive;
import com.scs.application.modules.msg.mapper.ReceiveMapper;
import com.scs.application.modules.msg.request.ReceiveQueryRequest;
import com.scs.application.modules.msg.service.ReceiveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 我的消息 service 实现
 *
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class ReceiveServiceImpl extends BaseServiceImpl<ReceiveMapper, Receive> implements ReceiveService {

    @Override
    public List<Receive> list(ReceiveQueryRequest request) {
        List<Receive> list = this.list(Wrappers.<Receive>query()
                .eq("receiver", getOAuthName())
                .orderByDesc("gmt_create")
        );
        return list;
    }

    @Override
    public IPage<Receive> page(ReceiveQueryRequest request) {
        IPage page = this.page(request.getPage(), Wrappers.<Receive>query()
                .eq("receiver", getOAuthName())
                .orderByDesc("gmt_create")
        );
        return page;
    }


    //未查看信息
    @Override
    public IPage<Receive> unReadPage(ReceiveQueryRequest request) {
        IPage page = this.page(request.getPage(), Wrappers.<Receive>query()
                .eq("receiver", getOAuthName())
                .eq("is_read", "0")
                .orderByDesc("gmt_create")
        );
        return page;
    }
    //未查看信息
    @Override
    public List<Receive> unReadList(ReceiveQueryRequest request) {
        List<Receive> list = this.list(Wrappers.<Receive>query()
                .eq("receiver", getOAuthName())
                .eq("is_read", "0")
                .orderByDesc("gmt_create")
        );
        return list;
    }

    /**
     * 获取登录用户
     *
     * @return
     */
    private String getOAuthName() {
        return UserUtils.currentUser().getNickname();
    }
}
